﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using KBEngineTool.Core;

namespace KBEngineTool
{
    [Serializable]
    public class ToolConfig : Singleton<ToolConfig>
    {
        [XmlAttribute]
        public string CSharpCodeDir = string.Empty;

        [XmlAttribute]
        public string TipsCodeDir = string.Empty;

        private string _toolConfigFile;
        public bool Load(string toolConfigFile)
        {
            if (File.Exists(_toolConfigFile))
            {
                using (FileStream f = new FileStream(_toolConfigFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    XmlSerializer x = new XmlSerializer(typeof(ToolConfig));
                    Inst = (ToolConfig)x.Deserialize(f);
                }
            }
            _toolConfigFile = toolConfigFile;
            return true;
        }
        public void Save()
        {
            XmlSerializer xml = new XmlSerializer(typeof(ToolConfig));
            using (FileStream fileStream = new FileStream(_toolConfigFile, FileMode.OpenOrCreate))
            { 
                xml.Serialize(fileStream, Inst);
            }
        }
    }
}
